import React, { Component } from 'react'
import './index.css'
export default class Footer extends Component {
  handleChecked = (event) => {
    console.log(event.target.checked)
    this.props.checkedAlltodos(event.target.checked)
  }
  clearAllDoneTodo = () => {
    this.props.clearAllDone()
  }
  render() {
    const { todoList } = this.props
    const doneCount = todoList.reduce((pre, current) => pre + (current.done ? 1 : 0), 0)
    return (
      <div className="footer">
        <label>
          <input type="checkbox" checked={doneCount === todoList.length && todoList.length !== 0} onChange={this.handleChecked} />
          <span>已完成{doneCount}/全部{todoList.length}</span>
        </label>
        <button onClick={this.clearAllDoneTodo}>清除已完成任务</button>
      </div>
    )
  }
}
